﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class SJZD_AddType : ATPages
{
    Function f = new Function();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            hidID1.Value = Request.QueryString["moduid"].ToString();
            lblTime.Text = DateTime.Now.ToShortDateString();
            lblUser.Text = Server.UrlDecode(Request.Cookies["user"].Values["realname"]);
            lblwz.Text = f.getModuleidAdd(Request["moduid"]);
            txtbh.Text = DateTime.Now.ToString();
            txtbh.Attributes.Add("onclick", "SelectDate('txtbh')");
            if (Request["action"] == "ch")
            {
                Label1.Text = "出库数量：";
                Label2.Text = "出库时间：";
                Label3.Text = "出库用途：";
                Label4.Text = "备注：";
                Label5.Text = "出库人：";
                btnSave.Text = " 出库 ";
            }
            if (Request["action"] == "jh")
            {
                Label1.Text = "进货数量：";
                Label2.Text = "进货时间：";
                Label3.Text = "货物用途：";
                Label4.Text = "备注：";
                Label5.Text = "进货人：";
                btnSave.Text = " 进货 ";
            }
            if (Request["action"] == "th")
            {
                Label1.Text = "退货数量：";
                Label2.Text = "退货时间：";
                Label3.Text = "退货原因：";
                Label4.Text = "备注：";
                Label5.Text = "退货人：";
                btnSave.Text = " 退货 ";
            }

        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(Request["id"]))
        {
            if (Request["action"] == "ch")
            {
                ZSql bjck = new ZSql();
                bjck.Open("insert into CS_Outbj (deptid,GuestId,MaintDate,MaintCode,SalesCode,DevicState,AuditDate,AuditUserName) values(" + Request["id"] + ",'" + Common.FormatParameter(txtType.Text) + "','" + Common.FormatParameter(txtbh.Text) + "','" + Common.FormatParameter(txtOrder.Text) + "','" + Common.FormatParameter(txtDescription.Text) + "','" + lblUser.Text + "','" + lblTime.Text + "','2')");
                ZSql numupdate = new ZSql();
                numupdate.Open("update CS_Stock set TotalNum=TotalNum-" + Convert.ToInt32(txtType.Text) + " where stockId=" + Request["id"] + "");
                ClientScript.RegisterStartupScript(typeof(Page), "aa", "selectInfo(" + Request["moduid"] + ")", true);
            }
            if (Request["action"] == "jh")
            {
                ZSql bjck = new ZSql();
                bjck.Open("insert into CS_Outbj (deptid,GuestId,MaintDate,MaintCode,SalesCode,DevicState,AuditDate,AuditUserName) values(" + Request["id"] + ",'" + Common.FormatParameter(txtType.Text) + "','" + Common.FormatParameter(txtbh.Text) + "','" + Common.FormatParameter(txtOrder.Text) + "','" + Common.FormatParameter(txtDescription.Text) + "','" + lblUser.Text + "','" + lblTime.Text + "','1')");
                ZSql numupdate = new ZSql();
                numupdate.Open("update CS_Stock set TotalNum=TotalNum+" + Convert.ToInt32(txtType.Text) + " where stockId=" + Request["id"] + "");
                ClientScript.RegisterStartupScript(typeof(Page), "aa", "selectInfo(" + Request["moduid"] + ")", true);
            }
            if (Request["action"] == "th")
            {
                ZSql bjck = new ZSql();
                bjck.Open("insert into CS_Outbj (deptid,GuestId,MaintDate,MaintCode,SalesCode,DevicState,AuditDate,AuditUserName) values(" + Request["id"] + ",'" + Common.FormatParameter(txtType.Text) + "','" + Common.FormatParameter(txtbh.Text) + "','" + Common.FormatParameter(txtOrder.Text) + "','" + Common.FormatParameter(txtDescription.Text) + "','" + lblUser.Text + "','" + lblTime.Text + "','3')");
                ZSql numupdate = new ZSql();
                numupdate.Open("update CS_Stock set TotalNum=TotalNum+" + Convert.ToInt32(txtType.Text) + " where stockId=" + Request["id"] + "");
                ClientScript.RegisterStartupScript(typeof(Page), "aa", "selectInfo(" + Request["moduid"] + ")", true);
            }
        }     
    } 
    
}
